local yaoyuan = fk.CreateSkill{
  name = "investiture__yaoyuan",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
  ["investiture__yaoyuan"] = "妖怨",
  [":investiture__yaoyuan"] = "锁定技，当你成为伤害牌的目标后，若上一张目标包括你的牌也为伤害牌，你进入隐匿状态。",

  ["$investiture__yaoyuan1"] = "一法幻千面~",
  ["$investiture__yaoyuan2"] = "能解一族之祸，形神俱灭又如何？",
}

local DIY = require "packages/diy_utility/diy_utility"

---@param player ServerPlayer
---@return Card[]
local function getCards(player)
  local cards = {}
  local room = player.room
  local all_events = room.logic.all_game_events
  for i = #all_events, 1, -1 do
    if #cards == 2 then break end
    if all_events[i].event == GameEvent.UseCard then
      local data = all_events[i].data ---@type UseCardData
      if data:hasTarget(player) then
        table.insert(cards, data.card)
      end
    end
  end
  return cards
end

yaoyuan:addEffect(fk.TargetConfirmed, {
  anim_type=  "defensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(yaoyuan.name) and player == target and data.card.is_damage_card then
      local cards = getCards(player)
      return #cards == 2 and table.every(cards, function(card) return card.is_damage_card end)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    DIY.enterHidden(player)
  end
})

return yaoyuan